package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.UrlDao;
import com.baizhi.springboot.entity.Url;
import com.baizhi.springboot.service.UrlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class UrlServiceImpl implements UrlService {
    @Autowired
    private UrlDao urlDao;

    @Override
    public Map selectUrlByPage(Integer page, Integer limit) {
        Integer offset=(page-1)*limit;
        List<Url> urls = urlDao.selectUrlByPage(offset, limit);
        Integer count = urlDao.selectCount();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", urls);
        return map;
    }

    @Override
    public void insertUrl(Url url) {
        urlDao.insertUrl(url);
    }

    @Override
    public void deleteUrl(Integer id) {
        urlDao.deleteUrl(id);
    }

    @Override
    public Url selectOneUrl(Integer id) {
        return urlDao.selectOneUrl(id);
    }

    @Override
    public void updateUrl(Url url) {
        urlDao.updateUrl(url);
    }
}
